package com.wxzz.elearing.course.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wxzz.elearing.course.entity.CurriculumCategory;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 课程分类 Mapper 接口
 * </p>
 *
 * @author
 * @since 2021-03-10
 */
public interface CurriculumCategoryMapper extends BaseMapper<CurriculumCategory> {

    /**
     * 查询二级分类
     *
     * @param pid
     * @return
     */
    @Select("SELECT * FROM `curriculum_category` WHERE pid = #{pid} AND deleted = 0 ORDER BY create_time DESC")
    List<CurriculumCategory> listCurriculumCategoryByPid(@Param("pid") Long pid);

    /**
     * 查询该分类平台课程总数
     *
     * @param platformCurriculumCategoryId
     * @return
     */
    @Select("SELECT COUNT(1) FROM `curriculum` WHERE platform_curriculum_category_id = #{platformCurriculumCategoryId} AND deleted = 0")
    Long countByPlatformCurriculumCategoryId(@Param("platformCurriculumCategoryId") Long platformCurriculumCategoryId);

    /**
     * 查询该分类企业课程总数
     *
     * @param enterpriseCurriculumCategoryId
     * @return
     */
    @Select("SELECT COUNT(1) FROM `curriculum` WHERE enterprise_curriculum_category_id = #{enterpriseCurriculumCategoryId} AND deleted = 0")
    Long countByEnterpriseCurriculumCategoryId(@Param("enterpriseCurriculumCategoryId") Long enterpriseCurriculumCategoryId);


    /**
     * 根据企业id与父级id列出分类搜索
     *
     * @param enterpriseId
     * @param pid
     * @return
     */
    @Select("SELECT * FROM `curriculum_category` WHERE enterprise_id = #{enterpriseId} AND pid = #{pid} AND deleted = 0 ")
    List<CurriculumCategory> listCurriculumCategoryByEnterpriseIdAndPid(@Param("enterpriseId") Long enterpriseId, @Param("pid") Long pid);

}
